#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 05-Nov-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;
using System.IO;
using System.Drawing;

using Thn;
#endregion

namespace Thn.Interface.Vcl.Themes.BlueSea
{
    /// <summary>
    /// Contains resources pertaining to Blue Sea theme
    /// </summary>
#if DEBUG
    public
#else
    public
#endif
 class BlueSeaTheme : ThemeBase
    {
        #region Fields
        string RootResourcePath = "Thn.Interface.Vcl.Resources.BlueSeaTheme.";
        #endregion

        #region On Get Name
        /// <summary>
        /// Gets the name of this theme.
        /// </summary>
        protected override string OnGetName()
        {
            return "BlueSea";
        }
        #endregion

        #region On Register Renderers
        /// <summary>
        /// Register <see cref="IControlRenderers"/> for all controls.
        /// </summary>
        protected override void OnRegisterRenderers()
        {
            RegisterRenderer(typeof(Label), new LabelRenderer());
            RegisterRenderer(typeof(LinkLabel), new LinkLabelRenderer());
            RegisterRenderer(typeof(Button), new ButtonRenderer());
            RegisterRenderer(typeof(ImageButton), new ImageButtonRenderer());
            RegisterRenderer(typeof(CheckBox), new CheckBoxRenderer());
            RegisterRenderer(typeof(ImageCheckBox), new ImageCheckBoxRenderer());
            RegisterRenderer(typeof(OptionBox), new OptionBoxRenderer());
            RegisterRenderer(typeof(ImageOptionBox), new ImageOptionBoxRenderer());
            RegisterRenderer(typeof(Calendar), new CalendarRenderer());
            RegisterRenderer(typeof(DateBox), new DateBoxRenderer());
            RegisterRenderer(typeof(TextBox), new TextBoxRenderer());
            RegisterRenderer(typeof(NumberBox), new NumberBoxRenderer());
            RegisterRenderer(typeof(ProgressBar), new ProgressBarRenderer());
            RegisterRenderer(typeof(Scroller), new ScrollerRenderer());
            RegisterRenderer(typeof(ListBox), new ListboxRenderer());
            RegisterRenderer(typeof(PopupListBox), new PopupListBoxRenderer());
            RegisterRenderer(typeof(WaitControl), new WaitControlRenderer());
            RegisterRenderer(typeof(Line), new LineRenderer());
            RegisterRenderer(typeof(IconBox), new IconBoxRenderer());
            RegisterRenderer(typeof(TabControl), new TabControlRenderer());
        }
        #endregion

        #region On Register Fonts
        /// <summary>
        /// Register all font styles.
        /// </summary>
        protected override void OnRegisterFonts()
        {
            Color cTextTitle = Color.FromArgb(77, 101, 122);
            Color cTextNormal = Color.FromArgb(77, 101, 122);
            Color cTextOver = Color.FromArgb(77, 101, 122);
            Color cTextSelected = Color.FromArgb(77, 101, 122);
            Color cTextDisabled = Color.DarkGray;
            Color cTextNull = Color.FromArgb(97, 121, 142);
            Color cTextTitles = Color.SteelBlue;

            //Textstyles
            AddFont(StyleNames.HeadingLarge, "Tahoma", 18, FontStyle.Bold, cTextTitles);
            AddFont(StyleNames.HeadingMiddle, "Tahoma", 13, FontStyle.Bold, cTextTitles);
            AddFont(StyleNames.HeadingSmall, "Tahoma", 10, FontStyle.Bold, cTextTitles);
            AddFont(StyleNames.Normal, "Tahoma", 9, FontStyle.Regular, cTextTitles);
            AddFont(StyleNames.Total, "Tahoma", 10, FontStyle.Bold, cTextTitles);
            AddFont(StyleNames.SubTotal, "Tahoma", 9, FontStyle.Bold, cTextTitles);
            AddFont(StyleNames.Comment, "Tahoma", 9, FontStyle.Italic, Color.FromArgb(0, 128, 0));
            AddFont(StyleNames.Hyperlink, "Tahoma", 9, FontStyle.Underline, Color.Blue);
            AddFont(StyleNames.Error, "Tahoma", 9, FontStyle.Bold, Color.Red);
            AddFont(StyleNames.Warning, "Tahoma", 9, FontStyle.Bold, Color.DarkOrange);
            AddFont(StyleNames.Important, "Tahoma", 9, FontStyle.Bold, Color.Red);
            AddFont(StyleNames.NullCaption, "Tahoma", 9, FontStyle.Italic, Color.DarkGray);

            //Button
            AddFont(StyleNames.ButtonNormal, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.ButtonOver, "Tahoma", 9f, FontStyle.Regular, cTextOver);
            AddFont(StyleNames.ButtonPressed, "Tahoma", 9f, FontStyle.Regular, cTextSelected);
            AddFont(StyleNames.ButtonDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);

            //CheckBox
            AddFont(StyleNames.CheckBoxChecked, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.CheckBoxUnchecked, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.CheckBoxCheckedDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);
            AddFont(StyleNames.CheckBoxUncheckedDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);

            //OptionBox
            AddFont(StyleNames.OptionBoxChecked, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.OptionBoxUnchecked, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.OptionBoxCheckedDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);
            AddFont(StyleNames.OptionBoxUncheckedDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);

            //Calendar
            AddFont(StyleNames.Calendar, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.CalendarTitle, "Arial Narrow", 10f, FontStyle.Bold, cTextNormal);
            AddSimpleShadowFont(StyleNames.CalendarTitleFocused, "Arial Narrow", 10f, FontStyle.Bold, Color.White, Color.FromArgb(30, 30, 30), 1, 1);
            AddFont(StyleNames.CalendarDayTitle, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.CalendarNormalDay, "Tahoma", 9f, FontStyle.Regular, Color.FromArgb(77, 101, 122));
            AddFont(StyleNames.CalendarSunday, "Tahoma", 9f, FontStyle.Regular, Color.Red);
            AddFont(StyleNames.CalendarOtherDay, "Tahoma", 9f, FontStyle.Regular, Color.FromArgb(176, 196, 222));
            AddFont(StyleNames.CalendarToday, "Tahoma", 9f, FontStyle.Regular, Color.Black);

            //Progress Bar
            AddFont(StyleNames.ProgressBar, "Arial Narrow", 9f, FontStyle.Bold, Color.White);

            //Edit Box            
            AddFont(StyleNames.EditboxTitle, "Tahoma", 9f, FontStyle.Regular, cTextTitle);
            AddFont(StyleNames.EditboxNormal, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.EditboxNull, "Arial Narrow", 9f, FontStyle.Italic, cTextNull);
            AddFont(StyleNames.EditboxOver, "Tahoma", 9f, FontStyle.Regular, cTextOver);
            AddFont(StyleNames.EditboxFocused, "Tahoma", 9f, FontStyle.Regular, cTextSelected);
            AddFont(StyleNames.EditboxDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);

            //List
            AddFont(StyleNames.List, "Tahoma", 9, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.ListHeading, "Arial Narrow", 10, FontStyle.Bold, cTextNormal);
            AddSimpleShadowFont(StyleNames.ListHeadingFocused, "Arial Narrow", 10f, FontStyle.Bold, Color.White, Color.FromArgb(30, 30, 30), 1, 1);

            //Tab
            AddFont(StyleNames.TabControlNormal, "Tahoma", 9f, FontStyle.Regular, cTextNormal);
            AddFont(StyleNames.TabControlOver, "Tahoma", 9f, FontStyle.Regular, cTextOver);
            AddFont(StyleNames.TabControlSelected, "Tahoma", 9f, FontStyle.Regular, cTextSelected);
            //AddFont(StyleNames.ButtonDisabled, "Tahoma", 9f, FontStyle.Regular, cTextDisabled);

            //Grid
            AddFont(StyleNames.GridHeading, "Tahoma", 9, FontStyle.Regular, cTextTitles);            
            AddFont(StyleNames.GridNormal, "Tahoma", 9, FontStyle.Regular, cTextTitles);
            AddFont(StyleNames.GridTotal, "Tahoma", 9.5f, FontStyle.Bold, cTextTitles);
            AddFont(StyleNames.GridSelection, "Arial Narrow", 10, FontStyle.Bold, cTextTitles);
        }
        #endregion

        #region On Register Images
        /// <summary>
        /// Register all image resources.
        /// </summary>
        protected override void OnRegisterImages()
        {
            AddImage(ImageNames.Add, "Add.png");
            AddImage(ImageNames.Cancel, "Cancel.png");
            AddImage(ImageNames.Check, "Check.png");
            AddImage(ImageNames.CheckBox_Checked, "CheckBox_Checked.png");
            AddImage(ImageNames.CheckBox_Checked_Disabled, "CheckBox_Checked_Disabled.png");
            AddImage(ImageNames.CheckBox_Unchecked, "CheckBox_Unchecked.png");
            AddImage(ImageNames.CheckBox_Unchecked_Disabled, "CheckBox_Unchecked_Disabled.png");
            AddImage(ImageNames.Close, "Close.png");
            AddImage(ImageNames.Config, "Config.png");
            AddImage(ImageNames.Connect, "Connect.png");
            //AddImage(ImageNames.Custom, "Custom.png");
            AddImage(ImageNames.Debug, "Debug.png");
            AddImage(ImageNames.Delete, "Delete.png");
            AddImage(ImageNames.Disconnect, "Disconnect.png");
            AddImage(ImageNames.Down, "Down.png");
            AddImage(ImageNames.DownPressed, "DownOver.png");
            AddImage(ImageNames.DownOver, "DownOver.png");
            AddImage(ImageNames.DownNormal, "DownNormal.png");
            //AddImage(ImageNames.UpPressed, "UpPressed.png");
            AddImage(ImageNames.UpOver, "UpOver.png");
            AddImage(ImageNames.UpNormal, "UpNormal.png");
            AddImage(ImageNames.Download, "Download.png");
            AddImage(ImageNames.Edit, "Edit.png");
            AddImage(ImageNames.Error, "Error.png");
            AddImage(ImageNames.Exit, "Exit.png");
            AddImage(ImageNames.Export, "Export.png");
            AddImage(ImageNames.Find, "Find.png");
            AddImage(ImageNames.First, "First.png");
            AddImage(ImageNames.Help, "Help.png");
            AddImage(ImageNames.Home, "Home.png");
            AddImage(ImageNames.Import, "Import.png");
            AddImage(ImageNames.Information, "Information.png");
            AddImage(ImageNames.Last, "Last.png");
            AddImage(ImageNames.Left, "Left.png");
            AddImage(ImageNames.Login, "Login.png");
            AddImage(ImageNames.Logout, "Logout.png");
            AddImage(ImageNames.New, "New.png");
            AddImage(ImageNames.Next, "Next.png");
            AddImage(ImageNames.Ok, "Ok.png");
            AddImage(ImageNames.Previous, "Previous.png");
            AddImage(ImageNames.Print, "Print.png");
            AddImage(ImageNames.PrintPreview, "PrintPreview.png");
            AddImage(ImageNames.Quit, "Quit.png");
            AddImage(ImageNames.OptionBox_Checked, "OptionBox_Checked.png");
            AddImage(ImageNames.OptionBox_Checked_Disabled, "OptionBox_Checked_Disabled.png");
            AddImage(ImageNames.OptionBox_Unchecked, "OptionBox_Unchecked.png");
            AddImage(ImageNames.OptionBox_Unchecked_Disabled, "OptionBox_Unchecked_Disabled.png");
            AddImage(ImageNames.Redo, "Redo.png");
            AddImage(ImageNames.Refresh, "Refresh.png");
            AddImage(ImageNames.Remove, "Remove.png");
            AddImage(ImageNames.Report, "Report.png");
            AddImage(ImageNames.Retry, "Retry.png");
            AddImage(ImageNames.Right, "Right.png");
            AddImage(ImageNames.Save, "Save.png");
            AddImage(ImageNames.Star, "Star.png");
            AddImage(ImageNames.Start, "Start.png");
            AddImage(ImageNames.Stop, "Stop.png");
            AddImage(ImageNames.Undo, "Undo.png");
            AddImage(ImageNames.Up, "Up.png");
            AddImage(ImageNames.Upload, "Upload.png");
            AddImage(ImageNames.Warning, "Warning.png");
            AddImage(ImageNames.Calendar_Today, "Calendar_Today.png");
            AddImage(ImageNames.Calendar_Selected, "Calendar_Selected.png");
        }
        #endregion

        #region Add Font
        /// <summary>
        /// Helper method for creating and registering a font style.
        /// </summary>
        void AddFont(string styleName, string fontName, float size, FontStyle style, Color color)
        {
            Font font = new Font(fontName, size, style);
            SimpleFontStyle s = new SimpleFontStyle(font, color);
            RegisterFontStyle(styleName, s);
        }

        /// <summary>
        /// Helper method for creating and registering a font style.
        /// </summary>
        void AddSimpleShadowFont(string styleName, string fontName, float size, FontStyle style, Color color, Color shadowColor, int offsetX, int offsetY)
        {
            Font font = new Font(fontName, size, style);
            SimpleShadowedFontStyle s = new SimpleShadowedFontStyle(font, color, shadowColor, offsetX, offsetY);
            RegisterFontStyle(styleName, s);
        }
        #endregion

        #region Add Image
        void AddImage(string styleName, string imageName)
        {
            Image img = LoadImage(RootResourcePath + imageName);

            if (img != null)
            {
                RegisterImage(styleName, img);
            }
            #region Defensive tracing
            else
            {
                throw new Exception("Could not find image " + imageName);
            }
            #endregion

        }
        #endregion

        #region Load an image from embeded resource
        /// <summary>
        /// Load Image from embeded resource
        /// </summary>
        Image LoadImage(string fullyQualifiedResourceName)
        {
            Image result = null;

            try
            {
                Type manifest = typeof(ResourceBeacon);

                Stream imgStream = manifest.Module.Assembly.GetManifestResourceStream(manifest, fullyQualifiedResourceName);

                if (imgStream != null)
                {
                    result = Image.FromStream(imgStream);
                }
            }
            catch { }

            return result;
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public BlueSeaTheme()
        { }
        #endregion
    }
}
